﻿$(document).ready(function () {
    documnetonload();
    ResizeImg();
});
function documnetonload() {
    $(".information").html(unescape($(".information").text()));
    $("#myImgs").loadthumb({
        "src": $("#myImgs").attr("src"),
        "imgId": "myImgs",
        "parentId": "imgdiv"
    });
    //$(".sellercount").corner("5px");
    $("#buydiv").bind("click", function () {
        if ($(this).hasClass("seller")) {
            $(this).toggleClass("seller");
            $(this).toggleClass("buyer");
            $("#selldiv").toggleClass("buyer");
            $("#selldiv").toggleClass("seller");
            $("#sellinfor").toggleClass("hideinfor");
            $("#buyinfor").toggleClass("hideinfor");
        }
    });
    $("#selldiv").bind("click", function () {
        if ($(this).hasClass("seller")) {
            $(this).toggleClass("seller");
            $(this).toggleClass("buyer");
            $("#buydiv").toggleClass("seller");
            $("#buydiv").toggleClass("buyer");
            $("#buyinfor").toggleClass("hideinfor");
            $("#sellinfor").toggleClass("hideinfor");
        }
    });
    $(".btn_add").bind("mouseover mouseout", function () {
        $(this).toggleClass("btn_add_y");
    });
    $(".btn_close").bind("mouseover mouseout", function () {
        $(this).toggleClass("btn_close_y");
    });
    $("#mainpage").hover(function () { $(this).addClass("mainActive"); }, function () { $(this).removeClass("mainActive"); });
    $("#buy").hover(function () { $(this).addClass("buylinkactive"); }, function () { $(this).removeClass("buylinkactive"); });
    $("#mybuy").hover(function () { $(this).addClass("mybuylinkactive"); }, function () { $(this).removeClass("mybuylinkactive"); });
    $("#allbuy").hover(function () { $(this).addClass("allbuylinkactive"); }, function () { $(this).removeClass("allbuylinkactive"); });
}
function ResizeImg() {
    var imgcount = $(".imgcss").length;
    for (var i = 0; i < imgcount; i++) {
        $($(".imgcss")[i]).loadthumb({
            "src": $(".imgcss")[i].src,
            "imgId": $(".imgcss")[i].id,
            "parentId": $($(".imgcss")[i]).parent()[0].id
        });
    }

    imgtip();

    $(".rowbackcolor").bind("mouseover mouseout", function () {
        $(this).toggleClass("rowbackcolor2");
    });

    $("a[disabled]").css({ border: "1px solid #999", color: "#999", "text-decoration": "none" });

    $(".sortspan").bind("mouseover", function () {
        $("#sortul").show();
    });
    $(".sortspan").bind("mouseout", function () {
        $("#sortul").hide();
    });
    $("#sortul").bind("mouseout", function () {
        $("#sortul").hide();
    });
    $("#sortul").bind("mouseover", function () {
        $("#sortul").show();
    });
}

function imgtip() {
    $(".tip").mouseover(function () {
        var $tip = $('<div id="tip"><div><img id="tipimg" src="' + $(this).attr("src") + '" /></div><s><i></i></s></div>');
        $("body").append($tip);
        $("#tip").show();
    }).mouseout(function () {
        $("#tip").remove();
    }).mousemove(function (e) {
        $("#tip").css({ "top": (e.pageY - 60) + "px", "left": (e.pageX + 30) + "px" })
    })
}

function addBuy(cpid) {
    $.ajax({
        type: "post",
        url: "AjaxWeb.aspx",
        data: {
            type: "addbuy",
            pid: cpid
        },
        beforeSend: function (XMLHttpRequest) { },
        success: function (data, textStatus) {
            if (data == "ok") {
                $.success('成功加入购买，在下面的卖家信息中可以查看卖家提供的商品!', "操作成功", function (action) {
                    if (action == "ok") {
                        window.location.reload();
                    }
                });
            }
            else if (data == "already") {
                $.success('你已经加入了购买，在下面的卖家信息中可以查看卖家提供的商品!', "操作成功", function (action) {
                    if (action == "ok") {
                        window.location.reload();
                    }
                });
            }
            else {
                userLogin(cpid);
            }
        },
        complete: function (XMLHttpRequest, textStatus) {

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.error('加入失败，请稍后再试!', '操作失败');
        }
    });
}
function userLogin() {
    asyncbox.open({
        id:"userlogin",
        url: '/otherpage/dialoglogin.htm',
        width: 518,
        height: 345,
        title: "用户登录",
        btnsbar: $.btn.OKCANCEL,
        callback: function (action, iframe) {
            //判断 action 值。
            if (action == 'ok') {
                //调用嵌入页面的checkuser方法
                iframe.checkuser();
                return false;
            }
        }

    });
}
function closebox() {
    $.close("userlogin");
    window.location.reload();
}
function closebuy(buyid) {
    asyncbox.confirm("您的购买还未到期，是否关闭?", "确认关闭", function (action) {
        if (action == "ok") {
            $.ajax({
                type: "post",
                url: "/AjaxCommand/CloseBuy.ashx",
                data: { type: "closebuy", buyid: buyid },
                beforeSend: function (XMLHttpRequest) {
                    asyncbox.open({
                        id: 'waitdialog',
                        title: '',
                        width: 330,
                        height: 115,
                        html: "<div class='dialogcss'><p><img src='/images/bigload.gif' style='vertical-align:middle;' /><label class='loadcss'><strong>&nbsp正在关闭，请稍等...</strong></label></p></div>"
                    });
                    $(".asyncbox_close").remove();
                },
                success:function(XMLHttpRequest, textStatus){
                    $.success("关闭成功", "成功", function (action) {
                        location.reload();
                    });
                },
                complete: function (XMLHttpRequest, textStatus) {
                    $.close("waitdialog");
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    alert("关闭购买失败，请稍后再试！");
                }
            });
        }
    });
}